package com.tedu.parkinglot.parkCard.service.impl;

import com.tedu.parkinglot.parkCard.mapper.UserParkCardMapper;
import com.tedu.parkinglot.parkCard.pojo.dto.UserParkCardSaveParam;
import com.tedu.parkinglot.parkCard.pojo.entity.UserParkCard;
import com.tedu.parkinglot.parkCard.service.UserParkCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class UserParkCardServiceImpl implements UserParkCardService {
    @Autowired
    private UserParkCardMapper userParkCardMapper;

    public List<UserParkCard> findAll() {
        return userParkCardMapper.findAll();
    }

    public UserParkCard findById(Long id) {
        return (UserParkCard) userParkCardMapper.findById(id).orElse(null);
    }


    public void save(UserParkCardSaveParam userParkCardSaveParam) {
        UserParkCard userParkCard = new UserParkCard();
        BeanUtils.copyProperties(userParkCardSaveParam, userParkCard);
        log.info("userParkCard:{}", userParkCard);
        if (userParkCard.getId() == null) {
            userParkCardMapper.save(userParkCard);
        }else {
            userParkCardMapper.update(userParkCard);
        }
    }



    public void delete(Long id) {
        userParkCardMapper.deleteById(id);
    }
}
